<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>prototype扩展数组方法</title>
</head>

<body>
    <script>
        const arr = [1, 2, 3, 4, 5]

        // 将求最大值方法挂载在prototype上
        Array.prototype.max = function () {
            return Math.max(...this)
        }

        console.log(arr.max()); // 5

        // 数组求和
        Array.prototype.sum = function () {
            return this.reduce((prev, current) => prev + current, 0)
        }
        console.log(arr.sum()); // 15
    </script>
</body>

</html>